const { execSync } = require("child_process");
const fs = require("fs");

console.log("开始简单测试src目录下的脚本...\n");

// 确保必要的目录存在
const dirs = ["./input/dat", "./input/mp3", "./temp/srt", "./temp/imgs", "./output/videos"];
dirs.forEach(dir => {
  if (!fs.existsSync(dir)) {
    fs.mkdirSync(dir, { recursive: true });
  }
});

// 创建测试用的 .dat 文件
const testDatContent = `1 This is a test sentence for testing purposes.
2 Another test sentence to check the conversion functionality.
3 A third sentence to ensure everything works correctly.`;

fs.writeFileSync("./input/dat/1.dat", testDatContent, "utf-8");
console.log("✓ 已创建测试用的 .dat 文件\n");

try {
  // 测试 convert_dat_to_ass.js 脚本
  console.log("1. 测试 convert_dat_to_ass.js...");
  execSync("node src/convert_dat_to_ass.js 1.dat", { stdio: "inherit" });
  console.log("✓ convert_dat_to_ass.js 测试通过\n");

  // 测试 convert_all.js 脚本
  console.log("2. 测试 convert_all.js...");
  execSync("node src/convert_all.js", { stdio: "inherit" });
  console.log("✓ convert_all.js 测试通过\n");

  console.log("测试完成！所有脚本都能正常运行。");
} catch (error) {
  console.error("！！！测试过程中出现错误:", error.message);
}
